package com.treeman.user.localization;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

public class LocalizationManager {

	private static Logger log = Logger.getLogger(LocalizationManager.class);

	private static LocalizationManager instance;

	private Map<String, UserLocalization> usersLocalization = new HashMap<String, UserLocalization>();

	private LocalizationManager() {
	}

	public static LocalizationManager getInstance() {
		if (instance == null)
			instance = new LocalizationManager();
		return instance;
	}

	public synchronized void changeUserLocalization(String username,
			UserLocalization localization) {
		usersLocalization.put(username, localization);
		log.debug("Changing user localization: " + username
				+ ". Current localization: lat=" + localization.getLatitude()
				+ " lon=" + localization.getLongitude());
	}

	public synchronized void removeUserLocalization(String username) {
		usersLocalization.remove(username);
		log.debug("Removing user localization: " + username);
	}

	public synchronized UserLocalization getUserLocalization(String username) {
		return usersLocalization.get(username);
	}
}
